package com.honey.serializable.json;

import com.honey.compilation.java.AbstractJavaCompilation;
import com.honey.compilation.java.Method;
import com.honey.core.types.FullyQualifiedJavaType;
import com.honey.core.types.JDKFullyQualifiedJavaType;
import com.honey.serializable.SerializableObjectMethod;

/**
 * 使用 com.google.gson.Gson ;
 * @author Administrator
 *
 */
public class GoogleGson implements SerializableObjectMethod {
	
	@Override
	public void appendJsonMethod(AbstractJavaCompilation abstractJavaCompilation) {
		Method jsonMethod = new Method("toJsonObject", JDKFullyQualifiedJavaType.getStringInstance());
		jsonMethod.addBodyLine("return new Gson().toJson(this)");
		abstractJavaCompilation.addImportedType(new FullyQualifiedJavaType("com.google.gson.Gson"));
		abstractJavaCompilation.addMethod(jsonMethod);
	}
	
}
